﻿
Partial Public Class Window2

    Public Color1 As System.Drawing.Color = System.Drawing.Color.Black
    Public Color2 As System.Drawing.Color = System.Drawing.Color.Black
    Public NewGradient As LinearGradientBrush
    Public GradientOffset As Double = 0.5
    Public ParentControl As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
        Dim dialog As New System.Windows.Forms.ColorDialog
        Dim offs As Double = GradientOffset
        dialog.ShowDialog()
        Color1 = dialog.Color
        If offs = 0 Then : offs = 0.5
        End If
        Dim gradient As New LinearGradientBrush
        Dim cl1 As Color
        cl1 = Color.FromArgb(Color1.A, Color1.R, Color1.G, Color1.B)
        Dim c2 As Color = Color.FromArgb(Color2.A, Color2.R, Color2.G, Color2.B)
        gradient.GradientStops.Add(New GradientStop(cl1, 0))
        gradient.GradientStops.Add(New GradientStop(c2, offs))
        Rectangle1.Fill = gradient
        NewGradient = gradient

    End Sub

    Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button2.Click
        Dim dialog As New System.Windows.Forms.ColorDialog
        dialog.ShowDialog()
        Dim offs As Double = GradientOffset
        Color2 = dialog.Color
        If offs = 0 Then : offs = 0.5
        End If
        Dim gradient As New LinearGradientBrush
        Dim cl1 As Color = Color.FromArgb(Color1.A, Color1.R, Color1.G, Color1.B)
        Dim cl2 As Color = Color.FromArgb(Color2.A, Color2.R, Color2.G, Color2.B)
        gradient.GradientStops.Add(New GradientStop(cl1, 0))
        gradient.GradientStops.Add(New GradientStop(cl2, offs))
        Rectangle1.Fill = gradient
        NewGradient = gradient
    End Sub

    Private Sub Slider1_ValueChanged(ByVal sender As Object, ByVal e As System.Windows.RoutedPropertyChangedEventArgs(Of Double)) Handles Slider1.ValueChanged
        Dim cl1 As Color = Color.FromArgb(Color1.A, Color1.R, Color1.G, Color1.B)
        Dim cl2 As Color = Color.FromArgb(Color2.A, Color2.R, Color2.G, Color2.B)
        Dim offs As Double = e.NewValue * 0.01
        GradientOffset = offs
        Dim Gradient As New LinearGradientBrush
        Gradient.GradientStops.Add(New GradientStop(cl1, 0))
        Gradient.GradientStops.Add(New GradientStop(cl2, offs))
        Try
            Rectangle1.Fill = Gradient
            NewGradient = Gradient
        Catch ex As Exception
        End Try

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button3.Click
        Select Case ParentControl
            Case "MainForm_CodeBox_BackGround"
                frm1.TextBox1.Background = NewGradient
                With My.Settings
                    .BG_Color1 = Color1
                    .BG_Color2 = Color2
                    .BG_Gradient = GradientOffset
                    My.Settings.Save()
                End With
            Case "MainForm_CodeBox_ForeGround"
                frm1.TextBox1.Foreground = NewGradient
                With My.Settings
                    .FG_Color1 = Color1
                    .FG_Color2 = Color2
                    .FG_Gradient = GradientOffset
                    My.Settings.Save()
                End With
        End Select
        Me.Close()
    End Sub
End Class
